package example.demo.threadpool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class DemoThreadPool {
    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor =
                new ThreadPoolExecutor(2, 4, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(20));
        threadPoolExecutor.execute(() -> {
            try {
                System.out.println(Thread.currentThread().getName() + "---start");
                TimeUnit.SECONDS.sleep(60);
                System.out.println(Thread.currentThread().getName() + "---end");
                System.out.println();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        threadPoolExecutor.submit(() -> {
            try {
                System.out.println(Thread.currentThread().getName() + "---start");
                TimeUnit.SECONDS.sleep(60);
                System.out.println(Thread.currentThread().getName() + "---end");
                System.out.println();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        System.out.println();
    }
}
